<?php
// 应用公共文件
namespace app\v\common;

//TP门面模块
use think\Facade;
//TPCache缓存模块
use think\facade\Cache;
//TPCookie门面
use think\facade\Cookie;

//system模型
use app\v\model\System as SystemModel;

class Common extends Facade
{
    //判断是否登入防止重复登入    
    protected static function identityOpposite(){
       
        $data = Cookie::get();
        if(!empty($data['UUID'])){
            $uuid = $data['UUID'];
            $cache = Cache::get($uuid);
            //判断缓存是否存在
            if(!empty($cache)){
                return true;
            }
        }
        return false;
    }

    protected static function systemData(){
        //主题响应
        $data = Cookie::get();
        if (empty($data['them-layout'])){
            //判断时间返回主题
            $h = date('H');
            if($h>=6 && $h<=20){
                $themLayout = "light";//主题色
            }else{
                $themLayout = "dark";//主题色
            }

        } else {
            $themLayout = $data['them-layout'];//主题色
        }

        //取system数据
        $system_data =  array_column(SystemModel::select()->toArray(), 'value','name');
        return [
            'siteKeywords'  => $system_data['siteKeywords'],
            'siteDes'  => $system_data['siteDes'],
            'nav'  => $system_data['siteName'],
            'siteName'  => $system_data['siteName'],
            'siteTitle'  => $system_data['siteTitle'],
            'siteFooter'  => $system_data['siteFooter'],
            'siteCopyright'  => $system_data['siteCopyright'],
            'siteTitle'  => $system_data['siteTitle'],
            'themLayout'  => $themLayout,
            
            'identityOpposite'  => Common::identityOpposite(),//登入状态 true/false
        ];
    }
}
